package com.ftg.learn.util.config;

import com.aliyun.oss.OSS;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 方法封闭类
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/5/16 下午3:02
 */
@Component
public class OssUtil {

    @Resource
    private OSS ossClient;

    /**
     * 通用处理类，用来完成java上传文件 到oss里
     *
     * @param file       文件流
     * @param bucketName 桶名称
     * @param objectName 文件名称
     */
    public void uploadFile(MultipartFile file, String bucketName, String objectName) {
        try {
            ossClient.putObject(bucketName, objectName, file.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
